#include <vector>
#include <string>
#include <iostream>
#include <cmath>
using namespace std;
/*
任意进制数转为10进制
*/
int fun1(vector<int> v, int n)
{
	int sum = 0;
	for (int i = 0; i < v.size(); i++)
	{
		sum += (v[i] * pow(n, (v.size() - 1 - i)));
	}
	return (int)sum;
}
/*
输入格式：
n 进制
123 具体数值
m 想要转为的进制数
*/
int main()
{
	int n, m, ten, yv;
	string s;
	cin >> n >> s >> m;
	vector<int> iv(s.length()), ov(0);//iv :inputVector
	for (int i = 0; i < s.length(); i++)
	{
		iv[i] = s[i] - '0';
	}
	ten = fun1(iv, n);
	do
	{
		yv = ten % m;
		ov.insert(ov.begin(), yv);
		ten = ten / m;
	} while (ten != 0);
	for (int i = 0; i < ov.size(); i++)
	{
		cout << ov[i];
	}
	cout << endl;
	return 0;
}